﻿// Autore: Mattia Barrasso

using RecipesManager.Data;
using White.Core;
using White.Core.UIItems;
using White.Core.UIItems.ListBoxItems;
using White.Core.UIItems.WindowItems;

namespace RecipesManager.Specs.Negozio
{
    class NegoziBDD
    {
        protected readonly string ShopManagerTitle = "Gestione Negozi";
        protected Window MainWindow;
        protected Application Application;

        protected Button NewShop;
        protected Button RemoveShop;
        protected Button BackToMainMenu;
        protected ListBox Shops;
        protected Button SearchShop;
        protected TextBox SearchedShop;

        protected TextBox ShopName;
        protected TextBox ShopAddress;
        protected TextBox ShopCity;
        protected TextBox ShopTelephone;
        protected TextBox ShopOpeningTimes;
        protected ComboBox Ingredients;
        protected IUIItem SelectedIngredients;
        protected Button AddIngredient;
        protected Button RemoveIngredient;

        protected Button SaveShop;
        protected Button CloseShop;

        protected void GetShopsUi()
        {
            NewShop = MainWindow.Get<Button>("bt_add");
            RemoveShop = MainWindow.Get<Button>("bt_delete");
            BackToMainMenu = MainWindow.Get<Button>("bt_back");
            Shops = MainWindow.Get<ListBox>("lb_items");
            SearchShop = MainWindow.Get<Button>("bt_search");
            SearchedShop = MainWindow.Get<TextBox>("tb_search");
        }

        protected void GetSingleShopUi()
        {
            ShopName = MainWindow.Get<TextBox>("tb_nomeNegozio");
            ShopAddress = MainWindow.Get<TextBox>("tb_indirizzoNegozio");
            ShopCity = MainWindow.Get<TextBox>("tb_cittaNegozio");
            ShopTelephone = MainWindow.Get<TextBox>("tb_telefonoNegozio");
            ShopOpeningTimes = MainWindow.Get<TextBox>("tb_orarioNegozio");

            Ingredients = MainWindow.Get<ComboBox>("cb_ingr");
            SelectedIngredients = MainWindow.Get<ListView>("grid_ingr");
            AddIngredient = MainWindow.Get<Button>("agg_button");
            RemoveIngredient = MainWindow.Get<Button>("canc_button");

            SaveShop = MainWindow.Get<Button>("save_button");
            CloseShop = MainWindow.Get<Button>("close_button");
        }

        protected void SetUpScenario()
        {
            Manager.ClearDatabase();
            Manager.Measures.Add("grammi", "gr", MeasureType.Weight, MeasureFamily.Metric, 1);
            Manager.Measures.Add("PesoTest", "PT", MeasureType.Weight, MeasureFamily.Metric, 1);
            Application = Application.Launch(@"..\..\..\RecipesManager\bin\x86\WhiteTesting\RecipesManager.exe");
            MainWindow = Application.GetWindow("Recipes Manager");
        }

        protected void TearDownScenario()
        {
            Manager.ClearCache();
            Manager.ClearDatabase();
            Application.Kill();
        }

        protected void NavigateToShops()
        {
            MainWindow.Get<Button>("negozi").Click();
            MainWindow = Application.GetWindow(ShopManagerTitle);
        }

        protected void NavigateToMainMenu()
        {
            MainWindow.Get<Button>("bt_back").Click();
            MainWindow = Application.GetWindow("Recipes Manager");
        }
    }
}
